#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#include<ext/rope>
#define rep(i,l,r) for(int i=(l),i##end=(r);i<=i##end;++i)
#define per(i,r,l) for(int i=(r),i##end=(l);i>=i##end;--i)
#define ll long long
#define int ll
#define double long double
#define pii pair<int,int>
#define fi first
#define se second
#define pb push_back
#define popcnt __builtin_popcount
#define rbtree(way) tree<way,null_type,less<way>,rb_tree_tag,tree_order_statistics_node_update>
using namespace std;
using namespace __gnu_cxx;
using namespace __gnu_pbds;
const int maxn=1e6+10,maxm=1e6+10,mod=998244353,inf=INT_MAX;
inline int ksm(int x,int k,int mod=mod){
	int ans=1;
	for(x%=mod;k;k>>=1,x=x*x%mod) if(k&1) ans=ans*x%mod;
	return ans;
}

int n,m;
string s[maxn];

signed main(){
	freopen("indian.in","r",stdin),freopen("indian.out","w",stdout);
	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	cin>>n>>m;
	rep(i,1,n) cin>>s[i],s[i]=' '+s[i]+' ';
	rep(i,1,m+2) s[0]+=' ',s[n+1]+=' ';
	rep(i,1,n) rep(j,1,m) if(s[i][j]=='#') if(i%5==0&&j%5==1||
		i%5==1&&j%5==3||i%5==2&&j%5==0||i%5==3&&j%5==2||i%5==4&&j%5==4) s[i][j]='1';
	rep(i,1,n) rep(j,1,m) if(s[i][j]=='#'&&s[i-1][j]!='1'&&
		s[i][j-1]!='1'&&s[i+1][j]!='1'&&s[i][j+1]!='1') s[i][j]='1';
	rep(i,1,n){
		rep(j,1,m) cout<<(s[i][j]=='1'?'1':s[i][j]=='.'?'.':'0');
		cout<<'\n';
	}
	return 0;
}
